package com.tamtamy.jtta.data.xml;

import java.util.ArrayList;
import java.util.Iterator;
import org.w3c.dom.Document;
import com.tamtamy.jtta.data.Tag;
import com.tamtamy.jtta.data.TagList;
import com.tamtamy.jtta.utility.XMLUtility;

public class XMLTagList extends TagList{	

	private static final long serialVersionUID = 8347126203275803934L;

	public XMLTagList(Document xmlDocument, String fieldName){
		super(getTagsListFromStringArray(xmlDocument, fieldName));				
	}
	
	public XMLTagList(Document xmlDocument){
		super(getTagsListFromStringArray(xmlDocument, "list"));				
	}
	
	public static ArrayList<Tag> getTagsListFromStringArray(Document xmlDocument, String fieldName) {
		ArrayList<Tag> tagsList = new ArrayList<Tag>();
		ArrayList<String> tagsStringList = XMLUtility.getStringList(xmlDocument,fieldName, "string");
		for (Iterator<String> iterator = tagsStringList.iterator(); iterator.hasNext();) {
			String tagName = (String) iterator.next();
			Tag tag = new Tag(tagName);
			tagsList.add(tag);
		}
		return tagsList;
	}
	
}
